package q2410_matchPlayersAndTrainers;

import java.util.Arrays;

public class Solution {
    /*
    排序后贪心的从后往前匹配运动员和教练
    即可解决
     */
    public int matchPlayersAndTrainers(int[] players, int[] trainers) {
        Arrays.sort(players);
        Arrays.sort(trainers);
        int ans = 0;
        int idx1 = players.length - 1, idx2 = trainers.length - 1;
        while (idx1 >= 0 && idx2 >= 0) {
            if (players[idx1] <= trainers[idx2]) {
                ++ans;
                idx2--;
            }
            idx1--;
        }
        return ans;
    }
}
